package com.bootdo.market.controller;

import com.alibaba.fastjson.JSON;
import com.bootdo.common.utils.PageUtils;
import com.bootdo.common.utils.Query;
import com.bootdo.common.utils.R;
import com.bootdo.market.dao.CommonDao;
import com.bootdo.market.dao.DuplicateDao;
import com.bootdo.market.domain.ThirdSdkAdvunionAdvpositionRelationshipDO;
import com.bootdo.market.service.ThirdSdkAdvunionAdvpositionRelationshipService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * 变现方广告联盟广告位关联表
 *
 * @author jinse
 * @email market@jinse.com
 * @date 2019-04-28 15:38:53
 */

@Controller
@RequestMapping("/market/thirdSdkAdvunionAdvpositionRelationship")
public class ThirdSdkAdvunionAdvpositionRelationshipController {
    @Autowired
    private ThirdSdkAdvunionAdvpositionRelationshipService thirdSdkAdvunionAdvpositionRelationshipService;
    @Autowired
    private CommonDao commonDao;
    @Autowired
    private DuplicateDao duplicateDao;

    @GetMapping()
    @RequiresPermissions("market:thirdSdkAdvunionAdvpositionRelationship:thirdSdkAdvunionAdvpositionRelationship")
    String ThirdSdkAdvunionAdvpositionRelationship(Integer unionaccountid, Model model) {
        model.addAttribute("unionaccountid", unionaccountid);
        return "market/thirdSdkAdvunionAdvpositionRelationship/thirdSdkAdvunionAdvpositionRelationship";
    }

    @ResponseBody
    @GetMapping("/list")
    @RequiresPermissions("market:thirdSdkAdvunionAdvpositionRelationship:thirdSdkAdvunionAdvpositionRelationship")
    public PageUtils list(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);
        List<ThirdSdkAdvunionAdvpositionRelationshipDO> thirdSdkAdvunionAdvpositionRelationshipList = thirdSdkAdvunionAdvpositionRelationshipService.list(query);
        int total = thirdSdkAdvunionAdvpositionRelationshipService.count(query);
        PageUtils pageUtils = new PageUtils(thirdSdkAdvunionAdvpositionRelationshipList, total);
        return pageUtils;
    }

    @GetMapping("/add")
    @RequiresPermissions("market:thirdSdkAdvunionAdvpositionRelationship:add")
    String add(Integer unionaccountid, Model model) {
        model.addAttribute("unionaccountid", unionaccountid);
        return "market/thirdSdkAdvunionAdvpositionRelationship/add";
    }


    @RequestMapping(value = "/listRelaIdthirdSdk", method = {RequestMethod.POST, RequestMethod.GET})
    @ResponseBody
    public String listRelaIdthirdSdk(HttpServletRequest request, ThirdSdkAdvunionAdvpositionRelationshipDO thirdSdkAdvunionAdvpositionRelationship) {
        List<Map<String, Object>> usedthirdSdklist = commonDao.listRelaIdthirdSdk(thirdSdkAdvunionAdvpositionRelationship.getUnionaccountid());
        return JSON.toJSONString(usedthirdSdklist);
    }

    @GetMapping("/edit")
    @RequiresPermissions("market:thirdSdkAdvunionAdvpositionRelationship:edit")
    String edit(ThirdSdkAdvunionAdvpositionRelationshipDO thirdSdkAdvunionAdvpositionRelationshipDO, Model model) {
        ThirdSdkAdvunionAdvpositionRelationshipDO thirdSdkAdvunionAdvpositionRelationship = thirdSdkAdvunionAdvpositionRelationshipService.get(thirdSdkAdvunionAdvpositionRelationshipDO.getId());
        model.addAttribute("unionaccountid", thirdSdkAdvunionAdvpositionRelationshipDO.getUnionaccountid());
        model.addAttribute("thirdSdkAdvunionAdvpositionRelationship", thirdSdkAdvunionAdvpositionRelationship);
        return "market/thirdSdkAdvunionAdvpositionRelationship/edit";
    }

    /**
     * 保存
     */
    @ResponseBody
    @PostMapping("/save")
    @RequiresPermissions("market:thirdSdkAdvunionAdvpositionRelationship:add")
    public R save(ThirdSdkAdvunionAdvpositionRelationshipDO thirdSdkAdvunionAdvpositionRelationship) {
        if (thirdSdkAdvunionAdvpositionRelationshipService.save(thirdSdkAdvunionAdvpositionRelationship) > 0) {
            return R.ok();
        }
        return R.error();
    }

    /**
     * 修改
     */
    @ResponseBody
    @RequestMapping("/update")
    @RequiresPermissions("market:thirdSdkAdvunionAdvpositionRelationship:edit")
    public R update(ThirdSdkAdvunionAdvpositionRelationshipDO thirdSdkAdvunionAdvpositionRelationship) {
        thirdSdkAdvunionAdvpositionRelationshipService.update(thirdSdkAdvunionAdvpositionRelationship);
        return R.ok();
    }

    /**
     * 删除
     */
    @PostMapping("/remove")
    @ResponseBody
    @RequiresPermissions("market:thirdSdkAdvunionAdvpositionRelationship:remove")
    public R remove(Integer id) {
        if (thirdSdkAdvunionAdvpositionRelationshipService.remove(id) > 0) {
            return R.ok();
        }
        return R.error();
    }

    /**
     * 删除
     */
    @PostMapping("/batchRemove")
    @ResponseBody
    @RequiresPermissions("market:thirdSdkAdvunionAdvpositionRelationship:batchRemove")
    public R remove(@RequestParam("ids[]") Integer[] ids) {
        thirdSdkAdvunionAdvpositionRelationshipService.batchRemove(ids);
        return R.ok();
    }

    @RequestMapping(value = "/advunionAdvpositionJudgingUniqueAdd", method = {RequestMethod.POST, RequestMethod.GET})
    @ResponseBody
    public R advunionAdvpositionJudgingUniqueAdd(HttpServletRequest request, @RequestParam Map<String, Object> params) {
        Map<String, Object> aa = duplicateDao.advunionAdvpositionJudgingUniqueAdd(params);
        if (aa == null) {
            return R.ok();
        } else {
            return R.error();
        }
    }

    @RequestMapping(value = "/advunionAdvpositionJudgingUniqueEdit", method = {RequestMethod.POST, RequestMethod.GET})
    @ResponseBody
    public R advunionAdvpositionJudgingUniqueEdit(HttpServletRequest request, @RequestParam Map<String, Object> params) {
        Map<String, Object> aa = duplicateDao.advunionAdvpositionJudgingUniqueEdit(params);
        if (aa == null) {
            return R.ok();
        } else {
            return R.error();
        }
    }
}
